#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve(){
    ll n, k;
    cin >> n >> k;
    map<int, int> mp;
    int x;
    ll ans = 0, f = -1;
    for(int i = 0; i < n; i++){
        cin >> x;
        if(x % k == 0) continue;
        int t = k - (x % k);
        mp[t]++;
        if(mp[t] > ans || (mp[t] == ans && f < t)){
            ans = mp[t];
            f = t;
        }
    }
    cout << (ans - 1) * k + (f + 1) << endl;
}

int main(){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}